#lang racket


(require "../base/main.rkt")

(provide arc-angle
         arc-radius
         rectangle-coords
         spline-tangents)


(define (arc-angle radius sagitta)
  (* 2 (acos (- 1 (/ sagitta radius)))))

(define (arc-radius chord sagitta)
  (/
   (+ (* 4 (^2 sagitta)) (^2 chord))
   (* 8 sagitta)))

(define (rectangle-coords width length)
  (let ((width (/2 width))
        (length (/2 length)))
    (list
     (xyz (- width) (- length) 0)
     (xyz width (- length) 0)
     (xyz width length 0)
     (xyz (- width) length 0))))

(define (spline-tangents cs)
  (let ((c0 (first cs))
        (c1 (second cs))
        (c2 (second (reverse cs)))
        (c3 (last cs)))
    (let ((begin-tangent (sub-c c1 c0))
          (end-tangent (sub-c c3 c2)))
      (values begin-tangent end-tangent))))